package com.whmskj.xjlhsc.mobie.equipmentManage.controller;

import com.whmskj.xjlhbc.core.Page;
import com.whmskj.xjlhbc.db.DataSource;
import com.whmskj.xjlhbc.db.DataSourceType;
import com.whmskj.xjlhsc.controller.vo.Result;
import com.whmskj.xjlhsc.mobie.equipmentManage.entity.vo.*;
import com.whmskj.xjlhsc.mobie.equipmentManage.service.IMachineComparisonService;
import com.whmskj.xjlhsc.service.Sb02EquipmentCounterAccountService;
import com.whmskj.xjlhsc.view.service.DeviceRealTimeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author 张
 * @version 1.0
 */

@RestController
@RequestMapping("/mob/scan")
@Slf4j
@RequiredArgsConstructor
@Tag(description = "扫一扫", name = "扫一扫")
public class ScanOneScanController {
    @Autowired
    private Sb02EquipmentCounterAccountService sb02EquipmentCounterAccountService;
    @Autowired
    private DeviceRealTimeService deviceRealTimeService;
    @Autowired
    private IMachineComparisonService machineComparisonService;

    @GetMapping("/recentlyEnergy")
    @Operation(description = "最近7天电耗曲线")
    public Result recentlyEnergy(@RequestParam Integer deviceId){
        List<Map<String,Object>> list = deviceRealTimeService.recentlyEnergy(deviceId);
        return Result.success(list);
    }

    @GetMapping("workInfo")
    @Operation(description = "挡车信息")
    public Result workInfo(@RequestParam Integer mesId, @RequestParam String deviceName){
        CarBlockingVo carBlockingVo= sb02EquipmentCounterAccountService.workInfo(mesId,deviceName);
        return Result.success(carBlockingVo);
    }
    @GetMapping("realTime")
    @Operation(description = "实时信息")
    public Result realTime(@RequestParam Integer mesId, @RequestParam String deviceName){
        Object realTime= sb02EquipmentCounterAccountService.realTime(mesId,deviceName);
        return Result.success(realTime);
    }
    @GetMapping("productionCapacity")
    @Operation(description = "产能信息")
    public Result productionCapacity(@RequestParam Integer mesId, @RequestParam String deviceName) {
        List<ProductionCapacityVo> productionCapacityVos = sb02EquipmentCounterAccountService.yiledPower(mesId, deviceName);
        return Result.success(productionCapacityVos);
    }
    @GetMapping("stopList")
    @Operation(description = "停车记录")
    public Result stopList(@RequestParam Integer mesId, @RequestParam String deviceName) {
        List<RunStopCarVo> runStopCarVos = sb02EquipmentCounterAccountService.stopList(mesId, deviceName);
        return Result.success(runStopCarVos);
    }
    @GetMapping("capacityInfo")
    @Operation(description = "电能数据")
    public Result capacityInfo(@RequestParam Integer mesId, @RequestParam String deviceName) {
        ElectricalEnergyDataVO electricalEnergyDataVO = sb02EquipmentCounterAccountService.capacityInfo(mesId, deviceName);
        return Result.success(electricalEnergyDataVO);
    }
    @GetMapping("deviceCode")
    @Operation(description = "选择机台号")
    public Result deviceCode(@RequestParam Integer mesId, @RequestParam String deviceName) {
        List<MachineVO> machineVOS = sb02EquipmentCounterAccountService.deviceCode(mesId, deviceName);
        return Result.success(machineVOS);
    }
    @GetMapping("deviceCompareList")
    @Operation(description = "机台对比列表")
    public Result deviceCompareList(@RequestParam(value = "mesId",required = false) Integer mesId,
                                    @RequestParam(value = "mesId2",required = false)Integer mesId2,
                                    @RequestParam(value = "start",required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate start,
                                    @RequestParam(value = "end",required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate end
    ) {
        return Result.success(machineComparisonService.machineComparison(mesId, mesId2, start, end));
    }
    @GetMapping("partsList")
    @Operation(description = "专件信息")
    public Result partsList(@RequestParam Integer mesId, @RequestParam String deviceName) {
        List<SpecialInformationVO> specialInformationVOS = sb02EquipmentCounterAccountService.partsList(mesId, deviceName);
        return Result.success(specialInformationVOS);
    }
    @GetMapping("maintenanceList")
    @Operation(description = "维保信息")
    public Result maintenanceList(@RequestParam Integer mesId, @RequestParam String deviceName) {
        List<EquipmentMaintenanceVO> equipmentMaintenanceVOList = sb02EquipmentCounterAccountService.maintenanceList(mesId, deviceName);
        return Result.success(equipmentMaintenanceVOList);
    }

}
